package com.attilax.lang.process;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class ProcessX {

	//列出当前系统所有进程
	public static void main(String[] args) {
		
		
		 List<String> set=	getProcessList();
		 Collections.sort(set);
		 for (String string : set) {
		 System.out.println(string);
		}
		 
		 System.out.println( isExistProcess("PotPlayerMini64.exe"));
		
	    }

	public static boolean isExistProcess(String string) {
	List<String> li=	getProcessList();
//		Set<String> set=new HashSet<String>();
//		set.addAll(li);
	for (String line : li) {
		if(line.contains(string))
			return true;
	}
		
	
		return false;
	}

	public static List<String> getProcessList() {
		Set<String> set=new HashSet<String>();
		
	        BufferedReader br = null;
	        try {
	            Process proc = Runtime.getRuntime().exec("tasklist");
	            br = new BufferedReader(
	                    new InputStreamReader(proc.getInputStream()));
	 
	            System.out.println("Process info:");
	            String line;
	            while ((line = br.readLine()) != null) {
	              //  System.out.println(br.readLine());
	                set.add(line);
	            }
	        } catch (IOException e) {
	            e.printStackTrace();
	        } finally {
	            if (br != null) {
	                try {
	                    br.close();
	                } catch (Exception e) {
	                    e.printStackTrace();
	                }
	            }
	        }
	        List<String> li=new ArrayList<String>();
	         li.addAll(set);
			return li;
	}

}
